package com.kuang.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 *
 */
@Controller
@RequestMapping("/user")
public class LoginController {
    @RequestMapping("/main")
    public String main() {
        return "main";
    }

    @RequestMapping("/gologin")
    public String login() {
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpSession session, String username, String password , Model model) {
        System.out.println("写入");
        System.out.println("login" + username);
        System.out.println(password);
        // 把用户信息存到 SESSION
        session.setAttribute("userLoginInfo", username);
        model.addAttribute("username",username);
        return "main";
    }
    //退出登陆
    @RequestMapping("logout")
    public String logout(HttpSession session) throws Exception {
        // session 过期 (用户还要使用不建议销毁)
//        session.invalidate();
        session.removeAttribute("userLoginInfo");
        return "login";
    }
}
